[id].vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. <template>
  2. <div>
  3. <!-- 页面头部 -->
  4. <TopicHead></TopicHead>
  5. <!-- 商圈详情 -->
  6. <div class="topicInfoBox">
  7. <div class="inner">
  8. <!-- 详情头部 -->
  9. <div class="infoHead">
  10. <div class="left">
  11. <div class="userInfo left">
  12. <el-badge value="楼主" class="item" type="warning">
  13. <img :src="dataInfo.avatar" alt="">
  14. </el-badge>
  15. <span>{{ dataInfo.author }}</span>
  16. </div>
  17. <div class="headContent left">
  18. <h2>{{ dataInfo.title }}</h2>
  19. <p>
  20. 群聊:
  21. <span>{{ dataInfo.group_name }}</span>
  22. <button @click="joinGroup">加入群聊</button>
  23. </p>
  24. </div>
  25. </div>
  26. <div class="right">
  27. <div class="one" v-if="dataInfo.type == 1">科研</div>
  28. <div class="two" v-else-if="dataInfo.type == 2">维权</div>
  29. <div class="three" v-else-if="dataInfo.type == 3">讨论</div>
  30. <p>{{ dataInfo.updated_at }}</p>
  31. </div>
  32. </div>
  33. <!-- 详情页 文本+图片 -->
  34. <div class="infoContent" v-show="dataInfo.content">
  35. <div v-html="dataInfo.content"></div>
  36. </div>
  37. <div class="infoContent1" v-show="!dataInfo.content">
  38. <img src="../../static/topic/Document_empty.png" alt="">
  39. <span>可以看看大家的互动哦~</span>
  40. </div>
  41. <!-- 详情页评论 -->
  42. <div class="comment">
  43. <h3>评论</h3>
  44. <div class="commentList" v-for="item in replyList" v-show="page_total != 0">
  45. <div class="left">
  46. <img :src="item.avatar" alt="">
  47. <span class="name">{{ item.user_name }} : </span>
  48. <span class="context">{{ item.content }}</span>
  49. </div>
  50. <div class="right">
  51. <span class="time">{{ item.created_at }}</span>
  52. <!-- <span>回复</span> -->
  53. </div>
  54. </div>
  55. <div class="comment_empty" v-show="page_total == 0">
  56. <img src="../../static/topic/message_empty.png" alt="">
  57. <span>暂无评论</span>
  58. </div>
  59. </div>
  60. <!-- 分页 -->
  61. <div class="paginationBox" v-show="page_total != 0">
  62. <el-pagination background layout="prev, pager, next" :total="page_total" prev-text="上一页"
  63. next-text="下一页" :default-page-size="pageSize" @change="changePage" />
  64. </div>
  65. </div>
  66. </div>
  67. <div class="message">
  68. <div class="inner">
  69. <input v-model="content" placeholder="快来回复吧~" type="text" class="messageInput">
  70. <button class="btn" @click="addReply">确定</button>
  71. </div>
  72. </div>
  73. <!-- 页面底部 -->
  74. <!-- <HomeFoot></HomeFoot> -->
  75. <AdvertisingFoot></AdvertisingFoot>
  76. </div>
  77. </template>
  78. <script setup>
  79. //1.引用模块 start ---------------------------------------->
  80. //使用ref和reactive动态变量
  81. import { ref, reactive, onMounted } from 'vue'
  82. import { useRoute } from 'vue-router';
  83. //使用官方ssr请求模块
  84. import { useNuxtApp, useFetch } from '#app'
  85. //使用element-plus组件
  86. import { ElPagination, ElBadge, ElInput, ElMessage } from 'element-plus';
  87. // axios请求
  88. const nuxtApp = useNuxtApp();
  89. const axios = nuxtApp.$axios;
  90. //1.引用模块 end ---------------------------------------->
  91. //2.页面数据 start ---------------------------------------->
  92. const dataInfo = ref({})
  93. const groupId = ref('')
  94. const replyList = ref([]) //评论列表
  95. //分页
  96. const page = ref(1)
  97. const pageSize = ref(5)
  98. let page_total = ref(0)
  99. const content = ref('')
  100. //2.页面数据 end ---------------------------------------->
  101. //3.获取商圈详情 start ---------------------------------------->
  102. const route = useRoute();
  103. const id = route.params.id; // 获取传递的 id 参数
  104. //页码发生改变
  105. const changePage = (val) => {
  106. console.log(val);
  107. page.value = val
  108. getTopicReply()
  109. }
  110. // 商圈信息
  111. const getTopicInfo = () => {
  112. let data = new FormData()
  113. data.append('id', id)
  114. axios.post('chat/getTopicInfo', data).then(res => {
  115. console.log('商圈信息', res);
  116. dataInfo.value = res.data
  117. groupId.value = res.data.group_id
  118. console.log(groupId.value);
  119. })
  120. }
  121. // 回复商圈 列表
  122. const getTopicReply = () => {
  123. let data = new FormData()
  124. data.append('id', id)
  125. data.append('page', page.value)
  126. data.append('page_size', pageSize.value)
  127. axios.post('chat/getTopicReply', data).then(res => {
  128. console.log('回复商圈列表 ', res);
  129. // replyList.value = res.data.data
  130. // page_total.value = res.data.total
  131. replyList.value = res.data.data.sort((a, b) => {
  132. return new Date(b.created_at) - new Date(a.created_at);
  133. });
  134. page_total.value = res.data.total
  135. console.log(replyList);
  136. })
  137. }
  138. onMounted(() => {
  139. getTopicInfo(); //商圈信息
  140. getTopicReply(); //回复商圈列表
  141. })
  142. //加入群聊
  143. const joinGroup = () => {
  144. console.log(groupId.value);
  145. let data = new FormData()
  146. data.append('group_id', groupId.value)
  147. axios.post('chat/joinGroup', data).then(res => {
  148. console.log('加入群聊 ', res);
  149. if (res.code == 0) {
  150. ElMessage.error(res.message)
  151. } else if (res.code == 200) {
  152. ElMessage({
  153. message: '加入成功',
  154. type: 'success',
  155. })
  156. }
  157. })
  158. }
  159. // 回复商圈
  160. const addReply = () => {
  161. let data = new FormData()
  162. data.append('id', id)
  163. data.append('content', content.value)
  164. axios.post('chat/addReply', data).then(res => {
  165. console.log('回复商圈 ', res);
  166. if (res.code == 0) {
  167. ElMessage.error(res.message)
  168. getTopicReply();
  169. } else if (res.code == 200) {
  170. ElMessage({
  171. message: '回复成功',
  172. type: 'success',
  173. })
  174. content.value = ''
  175. getTopicReply();
  176. }
  177. })
  178. }
  179. //3.获取商圈详情 end ---------------------------------------->
  180. </script>
  181. <style lang="less" scoped>
  182. .topicInfoBox {
  183. .inner {
  184. width: 1200px;
  185. margin: 0 auto;
  186. //信息头部
  187. .infoHead {
  188. height: 200px;
  189. padding: 65px 0 60px 40px;
  190. border-bottom: 1px solid rgba(0, 0, 0, 0.10);
  191. box-sizing: border-box;
  192. >.left {
  193. .userInfo {
  194. margin-right: 90px;
  195. .item {
  196. margin-top: -5px;
  197. margin-right: -5px;
  198. :deep(.el-badge__content.is-fixed) {
  199. position: absolute;
  200. right: calc(1px + var(--el-badge-size) / 2);
  201. top: 0;
  202. transform: translateY(-31%) translateX(79%);
  203. z-index: var(--el-index-normal);
  204. }
  205. img {
  206. width: 66px;
  207. height: 66px;
  208. vertical-align: middle;
  209. border-radius: 50%;
  210. }
  211. }
  212. span {
  213. margin-left: 15px;
  214. font-family: Microsoft YaHei, Microsoft YaHei;
  215. font-weight: 400;
  216. font-size: 18px;
  217. color: #333333;
  218. }
  219. }
  220. .headContent {
  221. h2 {
  222. font-family: Microsoft YaHei, Microsoft YaHei;
  223. font-weight: bold;
  224. font-size: 20px;
  225. color: #333333;
  226. margin-bottom: 26px;
  227. }
  228. >p {
  229. font-family: Microsoft YaHei, Microsoft YaHei;
  230. font-weight: 400;
  231. font-size: 16px;
  232. color: #333333;
  233. button {
  234. width: 86px;
  235. height: 32px;
  236. background-color: #028e21;
  237. color: #fff;
  238. border: none;
  239. margin-left: 100px;
  240. }
  241. }
  242. }
  243. }
  244. >.right {
  245. position: relative;
  246. div {
  247. position: absolute;
  248. right: 0;
  249. top: 0;
  250. width: 71px;
  251. height: 32px;
  252. line-height: 32px;
  253. text-align: center;
  254. background-color: #d9f0d6;
  255. margin-bottom: 29px;
  256. font-family: Microsoft YaHei, Microsoft YaHei;
  257. font-weight: 400;
  258. font-size: 16px;
  259. color: #33B023;
  260. }
  261. .one {
  262. color: #FFAA33;
  263. background-color: #fbebd5;
  264. }
  265. .two {
  266. color: #33B023;
  267. background-color: #d5ecd2;
  268. }
  269. .three {
  270. color: #666;
  271. background-color: #ebebeb;
  272. }
  273. p {
  274. width: 150px;
  275. text-align: right;
  276. position: absolute;
  277. top: 62px;
  278. right: 0;
  279. }
  280. }
  281. }
  282. // 有详情信息
  283. .infoContent {
  284. overflow: hidden;
  285. padding: 40px 46px;
  286. font-family: Microsoft YaHei, Microsoft YaHei;
  287. font-size: 20px;
  288. line-height: 40px;
  289. }
  290. //没有详情信息
  291. .comment_empty,
  292. .infoContent1 {
  293. height: 300px;
  294. line-height: 260px;
  295. text-align: center;
  296. img {
  297. width: 78px;
  298. height: 78px;
  299. vertical-align: -25px;
  300. vertical-align: middle;
  301. margin-right: 20px;
  302. }
  303. span {
  304. font-family: Microsoft YaHei, Microsoft YaHei;
  305. font-weight: bold;
  306. font-size: 26px;
  307. color: #CCCCCC;
  308. }
  309. }
  310. //评论
  311. .comment {
  312. h3 {
  313. height: 100px;
  314. padding-top: 30px;
  315. box-sizing: border-box;
  316. border-bottom: 1px solid #E1E1E1;
  317. font-family: Microsoft YaHei, Microsoft YaHei;
  318. font-weight: 400;
  319. font-size: 22px;
  320. color: #000000;
  321. }
  322. .commentList {
  323. height: 112px;
  324. border: 1px solid #E1E1E1;
  325. background-color: #fafafa;
  326. margin-top: 20px;
  327. padding: 30px 30px;
  328. box-sizing: border-box;
  329. .left {
  330. img {
  331. width: 52px;
  332. height: 52px;
  333. border-radius: 50%;
  334. vertical-align: middle;
  335. margin-right: 15px;
  336. }
  337. .name {
  338. font-family: Microsoft YaHei, Microsoft YaHei;
  339. font-weight: 400;
  340. font-size: 16px;
  341. color: #333333;
  342. margin-right: 30px;
  343. }
  344. .context {
  345. font-family: Microsoft YaHei, Microsoft YaHei;
  346. font-weight: bold;
  347. font-size: 16px;
  348. color: #333333;
  349. }
  350. }
  351. .right {
  352. padding: 14px 0;
  353. .time {
  354. font-family: Microsoft YaHei, Microsoft YaHei;
  355. font-weight: 400;
  356. font-size: 16px;
  357. color: #999999;
  358. margin-right: 30px;
  359. }
  360. span {
  361. font-family: Microsoft YaHei, Microsoft YaHei;
  362. font-weight: 400;
  363. font-size: 16px;
  364. color: #333333;
  365. }
  366. }
  367. }
  368. // .comment_empty {
  369. // height: 200px;
  370. // line-height: 200px;
  371. // text-align: center;
  372. // img {
  373. // width: 78px;
  374. // height: 78px;
  375. // vertical-align: -25px;
  376. // margin-right: 20px;
  377. // }
  378. // span {
  379. // font-family: Microsoft YaHei, Microsoft YaHei;
  380. // font-weight: bold;
  381. // font-size: 26px;
  382. // color: #CCCCCC;
  383. // }
  384. // }
  385. }
  386. }
  387. }
  388. //评论回复
  389. .message {
  390. width: 100%;
  391. height: 145px;
  392. line-height: 145px;
  393. background-color: #ecf5ee;
  394. .inner {
  395. .messageInput {
  396. width: 1049px;
  397. height: 67px;
  398. outline: none;
  399. border: 1px solid #E1E1E1;
  400. background-color: #fafafa;
  401. font-family: Microsoft YaHei, Microsoft YaHei;
  402. font-weight: 400;
  403. font-size: 18px;
  404. color: #666;
  405. padding-left: 20px;
  406. box-sizing: border-box;
  407. }
  408. .btn {
  409. width: 115px;
  410. height: 40px;
  411. border: none;
  412. background-color: #028e21;
  413. color: #fff;
  414. border-radius: 6px;
  415. margin-left: 36px;
  416. font-family: Microsoft YaHei, Microsoft YaHei;
  417. font-weight: 400;
  418. font-size: 16px;
  419. }
  420. }
  421. }
  422. //分页
  423. .paginationBox {
  424. display: flex;
  425. justify-content: center;
  426. margin-top: 60px;
  427. margin-bottom: 90px;
  428. // 鼠标移入后字体颜色
  429. :deep(.el-pagination:hover) {
  430. color: #139609;
  431. }
  432. :deep(.el-pagination.is-background .btn-next),
  433. :deep(.el-pagination.is-background .btn-prev) {
  434. width: 70px;
  435. height: 34px;
  436. margin: 0px 10px;
  437. border-radius: 4px;
  438. }
  439. :deep(.el-pagination.is-background .el-pager li) {
  440. margin: 0px 10px;
  441. width: 38px;
  442. height: 34px;
  443. border-radius: 4px;
  444. }
  445. :deep(.el-pagination.is-background .btn-next.is-active),
  446. :deep(.el-pagination.is-background .btn-prev.is-active),
  447. :deep(.el-pagination.is-background .el-pager li.is-active) {
  448. background-color: #028e21;
  449. color: #fff;
  450. }
  451. }
  452. </style>